package com.whmskj.xjlhsc.mobie.equipment.controller;

import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.entity.WbRecord;
import com.whmskj.xjlhsc.jitapi.mapper.SparePartsMapper;
import com.whmskj.xjlhsc.mobie.equipment.controller.fo.RepairTaskListFo;
import com.whmskj.xjlhsc.service.WbRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: XJLHSC
 * @BelongsPackage: com.whmskj.xjlhsc.mobie.controller
 * @Author: lk
 * @CreateTime: 2025-06-23
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/mob/maintenanceTask")
@Slf4j
@Tag(description = "维保任务接口", name = "维保任务接口")
@RequiredArgsConstructor
public class MaintenanceController {

    private final WbRecordService wbRecordService;
    private final SparePartsMapper sparePartsMapper;


    @Operation(description = "查询维保监督列表")
    @GetMapping("/repairTaskList")
    public Result repairTaskList(RepairTaskListFo fo) {
        return Result.success(wbRecordService.getRepairTaskList(fo));
    }


    @GetMapping("/scanToProcess")
    @Operation(description = "扫码处理任务")
    public Result scanToProcess(@RequestParam Long recordId, @RequestParam Integer deviceId) {
        return Result.success(wbRecordService.scanToProcess(recordId, deviceId));
    }

    @GetMapping("/{id}")
    @Operation(description = "查询维保任务详情")
    public Result getTaskDetailInfo(@PathVariable Long id) {
        return Result.success(wbRecordService.findById(id));
    }

    @PostMapping("/taskSubmit")
    @Operation(description = "维保任务提交")
    public Result taskSubmit(@RequestBody WbRecord wbRecord) {
        return Result.success(wbRecordService.taskSubmit(wbRecord));
    }

    @PostMapping("/taskSubmitTemp")
    @Operation(description = "维保任务临时提交")
    public Result taskSubmitTemp(@RequestBody WbRecord wbRecord) {
        return Result.success(wbRecordService.taskSubmitTemp(wbRecord));
    }

    @PostMapping("/planDateChange")
    @Operation(description = "计划日期变更")
    public Result planDateChange(@RequestBody WbRecord wbRecord) {
        return Result.success(wbRecordService.updateById(wbRecord));
    }

    @GetMapping("/listBySpareParts")
    @Operation(description = "根据备件类型查询专备件")
    public Result listBySpareParts(@RequestParam String spareType,
                                   @RequestParam(required = false) String spareName,
                                   @RequestParam Integer deviceId) {
        return Result.success(sparePartsMapper.listBySpareParts(spareType,spareName,deviceId));
    }
    @PostMapping("/listSparePartsByIds")
    @Operation(description = "根据备件类型查询专备件")
    public Result listSparePartsByIds(@RequestBody List<Integer> ids) {
        return Result.success(sparePartsMapper.listSparePartsByIds(ids));
    }
}
